import request from '@/utils/request'

export default {
  // 新增搜索产品方法
  searchProducts(params) {
    return request({
      url: '/products/search',
      method: 'get',
      params: params
    });
  },

  // 获取所有分类
  getAllCategories() {
    return request({
      url: '/category/all',
      method: 'get'
    });
  },
  update(product) {
    return request({
      url: '/products/update',
      method: 'post',
      data: product
    });
  },
  deletePro(proid) {
    return request({
      url: '/products/delete',
      method: 'delete',
      params: {
        "id":proid
      }
    });
  },
  uploadImg(formData) {
    return request({
      url: '/qiniu/uploadImg',
      method: 'post',
      data: formData,  // 使用 FormData 作为请求数据
      headers: {
        'Content-Type': 'multipart/form-data',  // 自动设置为 multipart/form-data
      },
    });
  },
  list(pageInfo) { // 列表
    return request({
      url: '/products/list',
      method: 'get',
      params: {
        page: pageInfo.page,
        size: pageInfo.size
      }
    });
  },
  Mlist(pageInfo) { // 列表
    return request({
      url: '/products/Mlist',
      method: 'get',
      params: {
        page: pageInfo.page,
        size: pageInfo.size,
        keyword: pageInfo.keyword
      }
    });
  },
  //新增
  add(product) {
    return request({
      url: '/products/add',
      method: 'post',
      data: {
        categoryId: product.categoryId,
        productName: product.productName,
        description: product.description,
        price: product.price,
        stock: product.stock,
        imageUrl: product.imageUrl,
        netdiskUrl: product.netdiskUrl,
      }
    });
  },
  //修改
  getById(productId) {
    return request({
      url: '/products/getById/' + productId,
      method: 'get',
    });
  },
  pushComment(comment) { //
    return request({
      url: '/article/pushComment',
      method: 'post',
      data: {
        articleId: comment.articleId,
        parentId: comment.parentId,
        content: comment.content,
        replyCommentId: comment.replyCommentId
      }
    });
  },

}